home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_071 / airfoil / airfoil.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  18KB  |  485 lines

  1. /********************************************************************
  2. *                                                                   *
  3. * Joukowski Airfoil Generator with Streamlines and Pressure         *
  4. * Distribution Algorithm                                            *
  5. *                                                                   *
  6. * Written by:   Russell Leighton      15 March 1987                 *
  7. *               Lancaster, CA                                       *
  8. *                                                                   *
  9. ********************************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/nodes.h>
  13. #include <exec/lists.h>
  14. #include <exec/ports.h>
  15. #include <exec/devices.h>
  16. #include <devices/keymap.h>
  17. #include <graphics/regions.h>
  18. #include <graphics/copper.h>
  19. #include <graphics/gels.h>
  20. #include <graphics/gfxbase.h>
  21. #include <graphics/gfxmacros.h>
  22. #include <graphics/gfx.h>
  23. #include <graphics/clip.h>
  24. #include <graphics/view.h>
  25. #include <graphics/rastport.h>
  26. #include <graphics/layers.h>
  27. #include <intuition/intuition.h>
  28. #include <hardware/blit.h>
  29. #include <math.h>
  30. #include <libraries/mathffp.h>
  31.  
  32. #undef NULL
  33. #define NULL  ((void *)0)
  34. #define XMIN  0
  35. #define YMIN  0
  36. #define XMAX  639
  37. #define YMAX  399
  38. #define XCEN  320
  39. #define YCEN  210
  40. #define SFAC  100
  41. #define TOL   1.0e-8
  42. #define PENUP    (PEN = 0)
  43. #define PENDOWN  (PEN = 1)
  44.  
  45. unsigned int mask = 0;             /* one bit set for each open */
  46.  
  47. #define INTUITION  0x0001
  48. #define GRAPHICS   0x0002
  49. #define SCREEN     0x0004
  50. #define WINDOW     0x0008
  51. #define AREAFILL   0x0010
  52. #define DMREQUEST  0x0020
  53.  
  54. struct IntuitionBase *IntuitionBase;
  55. struct GfxBase *GfxBase;
  56. struct IntuiMessage *message;
  57. struct Message *GetMsg();
  58. struct ViewPort *vp;
  59. struct RastPort *rp;
  60. struct Screen *s;
  61. struct Window *w;
  62. struct Requester AirRequest;
  63. struct TmpRas trp;
  64. struct AreaInfo area;
  65.  
  66. WORD buffer[625];
  67. ULONG camber = 4,thickness = 6,angle = 0,velocity = 8;
  68. float a,b,c,t,r,alpha;
  69. int PEN,FILL,Continue = TRUE,mode = TRUE,title = FALSE;
  70. long ixo,iyo;
  71.  
  72. char *about[] = {
  73. "        Airfoil Generator Utilizing the Joukowski Transformation",
  74. " ",
  75. "        Written by:  Russell Leighton",
  76. "                     Lancaster, CA",
  77. "                     March 1987",
  78. " ",
  79. "        To use this program bring up the requester by double clicking",
  80. "        the right mouse button (the menu button).  This requester can be",
  81. "        brought up at any time (even during plotting) by double clicking",
  82. "        the right mouse button.  The requester gadgets are located and",
  83. "        described as follows.",
  84. " ",
  85. "        Gadget     Location                Description",
  86. "        ------     --------                -----------",
  87. " ",
  88. "        Quit       Upper left corner       Exits from program",
  89. "        Close      Upper right corner      Starts or continues plot",
  90. "        ShowTitle  Upper center            Toggles screen title bar",
  91. "        Airfoil    Below ShowTitle gadget  Toggles streamline/pressure plot",
  92. "        Camber     Below Airfoil gadget    Mid-chord camber entry",
  93. "        Thickness  Below Camber gadget     Mid-chord thickness entry",
  94. "        Angle      Below Thickness gadget  Angle of attack entry",
  95. "        Velocity   Bottom edge             Slider for velocity entry",
  96. " "
  97. };
  98.  
  99. UWORD colors[] = {
  100. 0x046, 0x000, 0xC00, 0xC60,
  101. 0xC90, 0xCC0, 0x0C0, 0x0C7,
  102. 0x0CC, 0x09C, 0x06C, 0x00C,
  103. 0x009, 0x006, 0x000, 0xCCC
  104. };
  105.  
  106. UWORD closeimage[] = {
  107. /* plane 0 */
  108. 0x3FFF, 0xFC00,
  109. 0x3000, 0x0C00,
  110. 0x33FF, 0xCC00,
  111. 0x33FF, 0xCC00,
  112. 0x33C3, 0xCC00,
  113. 0x33C3, 0xCC00,
  114. 0x33FF, 0xCC00,
  115. 0x33FF, 0xCC00,
  116. 0x3000, 0x0C00,
  117. 0x3FFF, 0xFC00
  118. };
  119.  
  120. UWORD streamimage[] = {
  121. /* plane 0 */
  122. 0x0000, 0x0000, 0x0000, 0x0000,
  123. 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  124. 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  125. 0xFFFF, 0xFFFF, 0xFFF0, 0x000F,
  126. 0xFC00, 0xFFE1, 0x003F, 0xFFFC,
  127. 0x03FF, 0xFFFE, 0x7FFF, 0xFFFE,
  128. 0x0000, 0xFFFC, 0x0000, 0x0000,
  129. 0xFFFE, 0x0003, 0xFFFF, 0xFFFF,
  130. 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  131. 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  132. 0xFFFF, 0xFFFF, 0x0000, 0x0000,
  133. /* plane 1 */
  134. 0x0000, 0x0000, 0x0000, 0x0000,
  135. 0x0000, 0x0000, 0x0000, 0x0000,
  136. 0x0000, 0x0000, 0x00FF, 0xFFF8,
  137. 0xFFF0, 0x000F, 0xFC0F, 0xFFF1,
  138. 0x03FF, 0x001E, 0xFFC0, 0x0003,
  139. 0xFC00, 0x0001, 0x8000, 0x0001,
  140. 0xFFFF, 0x0003, 0xFFFF, 0xFFFF,
  141. 0x0001, 0xFFFC, 0xFFFE, 0x0003,
  142. 0xFFFF, 0xFFFF, 0x0000, 0x01FE,
  143. 0x0000, 0x0000, 0x0000, 0x0000,
  144. 0x0000, 0x0000, 0x0000, 0x0000,
  145. /* plane 2 */
  146. 0x0000, 0x0000, 0x0000, 0x0000,
  147. 0x0000, 0x0000, 0xFFFF, 0xFFFF,
  148. 0xFF00, 0x0007, 0x00FF, 0xFFF8,
  149. 0xFFF0, 0x000F, 0xFC00, 0x0001,
  150. 0x0000, 0x0000, 0x0000, 0x0000,
  151. 0x0000, 0x0000, 0x0000, 0x0000,
  152. 0x0000, 0x0000, 0x0000, 0x0000,
  153. 0x0000, 0x0000, 0xFFFE, 0x0003,
  154. 0xFFFF, 0xFFFF, 0x0000, 0x01FE,
  155. 0xFFFF, 0xFE01, 0xFFFF, 0xFFFF,
  156. 0x0000, 0x0000, 0x0000, 0x0000
  157. };
  158.  
  159. UWORD pressureimage[] = {
  160. /* plane 0 */
  161. 0x0000, 0xFF80, 0x0007, 0x0060,
  162. 0x0038, 0x0010, 0x00C0, 0x0008,
  163. 0x0100, 0x0004, 0x0200, 0x0002,
  164. 0x0400, 0x0002, 0x0800, 0x0001,
  165. 0x1000, 0xFFE1, 0x203F, 0xFFFD,
  166. 0x43FF, 0xFFFE, 0x7FFF, 0xFFFE,
  167. 0x4000, 0xFFFD, 0x2000, 0x0001,
  168. 0x1000, 0x0002, 0x0C00, 0x0004,
  169. 0x0380, 0x0008, 0x0070, 0x0030,
  170. 0x000F, 0x00C0, 0x0000, 0xFF00,
  171. 0x0000, 0x0000, 0x0000, 0x0000,
  172. /* plane 1 */
  173. 0x0000, 0x0000, 0x0000, 0xFF80,
  174. 0x0007, 0xFFE0, 0x003F, 0xFFF0,
  175. 0x00FF, 0xFFF8, 0x01FF, 0xFFFC,
  176. 0x03FF, 0xFFFC, 0x07FF, 0xFFFE,
  177. 0x0FFF, 0x001E, 0x1FC0, 0x0002,
  178. 0x3C00, 0x0000, 0x0000, 0x0000,
  179. 0x3FFF, 0x0002, 0x1FFF, 0xFFFE,
  180. 0x0FFF, 0xFFFC, 0x03FF, 0xFFF8,
  181. 0x007F, 0xFFF0, 0x000F, 0xFFC0,
  182. 0x0000, 0xFF00, 0x0000, 0x0000,
  183. 0x0000, 0x0000, 0x0000, 0x0000
  184. };
  185.  
  186. SHORT title_xy[] = {
  187.      0,   0,
  188.    151,   0,
  189.    151,  10,
  190.      0,  10,
  191.      0,   0
  192. };
  193.  
  194. struct Border title_border = {
  195.    0L, 0L,                      /* LeftEdge, TopEdge */
  196.    1L, 1L, JAM1,                /* FrontPen, BackPen, DrawMode */
  197.    5L,                          /* Count (no. of vertices) */
  198.    &title_xy[0],                /* Pointer to coordinates */
  199.    NULL                         /* No NextBorder */
  200. };
  201.  
  202. struct Image quit_image = {
  203.    0L, 0L,                      /* LeftEdge, TopEdge */
  204.    24L, 10L, 1L,                /* Width, Height, Depth */
  205.    &closeimage[0],              /* Pointer to bit image */
  206.    0x2, 0x0,                    /* PlanePick, PlaneOnOff */
  207.    NULL                         /* No other images */
  208. };
  209.  
  210. struct Image close_image = {
  211.    0L, 0L,                      /* LeftEdge, TopEdge */
  212.    24L, 10L, 1L,                /* Width, Height, Depth */
  213.    &closeimage[0],              /* Pointer to bit image */
  214.    0x1, 0x0,                    /* PlanePick, PlaneOnOff */
  215.    NULL                         /* No other images */
  216. };
  217.  
  218. struct Image stream_image = {
  219.    0L, 0L,                      /* LeftEdge, TopEdge */
  220.    32L, 22L, 3L,                /* Width, Height, Depth */
  221.    &streamimage[0],             /* Pointer to bit image */
  222.    0xD, 0x0,                    /* PlanePick, PlaneOnOff */
  223.    NULL                         /* No other images */
  224. };
  225.  
  226. struct Image pressure_image = {
  227.    0L, 0L,                      /* LeftEdge, TopEdge */
  228.    32L, 22L, 2L,                /* Width, Height, Depth */
  229.    &pressureimage[0],           /* Pointer to bit image */
  230.    0x3, 0x0,                    /* PlanePick, PlaneOnOff */
  231.    NULL                         /* No other images */
  232. };
  233.  
  234. struct Image prop_image;
  235.  
  236. struct IntuiText camber_text = {1L,1L,JAM1,2L,-11L,NULL,
  237.    (UBYTE *)"Camber (% of chord):",NULL};
  238.  
  239. struct IntuiText thick_text = {1L,1L,JAM1,2L,-11L,NULL,
  240.    (UBYTE *)"Thickness (% of chord):",NULL};
  241.  
  242. struct IntuiText angle_text = {1L,1L,JAM1,2L,-11L,NULL,
  243.    (UBYTE *)"Angle of attack (deg):",NULL};
  244.  
  245. struct IntuiText velocity_text = {1L,1L,JAM1,2L,-11L,NULL,
  246.    (UBYTE *)"+       Velocity       -",NULL};
  247.  
  248. #define BUFSIZE 16
  249. UBYTE CambBuf[BUFSIZE] = "4";
  250. UBYTE ThicBuf[BUFSIZE] = "6";
  251. UBYTE AnglBuf[BUFSIZE] = "0";
  252. UBYTE UndoBuf[BUFSIZE];
  253.  
  254. struct StringInfo camber_string = {
  255.    CambBuf,                     /* Buffer */
  256.    UndoBuf,                     /* UndoBuffer */
  257.    0L,                          /* BufferPos */
  258.    BUFSIZE,                     /* MaxChars */
  259.    0L,0L,                       /* DispPos, UndoPos */
  260.    8L,                          /* NumChars */
  261.    0L,0L,0L,                    /* Posn Vars calc by intuition */
  262.    NULL,                        /* No pointer to layer */
  263.    0L,                          /* Longint value returned */
  264.    NULL                         /* No AltKeyMap */
  265. };
  266.  
  267. struct StringInfo thick_string = {
  268.    ThicBuf,                     /* Buffer */
  269.    UndoBuf,                     /* UndoBuffer */
  270.    0L,                          /* BufferPos */
  271.    BUFSIZE,                     /* MaxChars */
  272.    0L,0L,                       /* DispPos, UndoPos */
  273.    8L,                          /* NumChars */
  274.    0L,0L,0L,                    /* Posn Vars calc by intuition */
  275.    NULL,                        /* No pointer to layer */
  276.    0L,                          /* Longint value returned */
  277.    NULL                         /* No AltKeyMap */
  278. };
  279.  
  280. struct StringInfo angle_string = {
  281.    AnglBuf,                     /* Buffer */
  282.    UndoBuf,                     /* UndoBuffer */
  283.    0L,                          /* BufferPos */
  284.    BUFSIZE,                     /* MaxChars */
  285.    0L,0L,                       /* DispPos, UndoPos */
  286.    8L,                          /* NumChars */
  287.    0L,0L,0L,                    /* Posn Vars calc by intuition */
  288.    NULL,                        /* No pointer to layer */
  289.    0L,                          /* Longint value returned */
  290.    NULL                         /* No AltKeyMap */
  291. };
  292.  
  293. struct PropInfo velocity_prop = {
  294.    AUTOKNOB |                   /* Select auto-knob gadget */
  295.    FREEHORIZ,                   /* Knob can move horizontal */
  296.    0x7FFF, 0x0000,              /* Initially knob is at center */
  297.    0x0800, 0x0000,              /* HorizBody, VertBody */
  298.    200L,11L,                    /* CWidth, CHeight */
  299.    1L,1L,                       /* HPotRes, VPotRes */
  300.    0L,0L                        /* LeftBorder, TopBorder */
  301. };
  302.  
  303. #define CAMBER_GAD 0
  304. struct Gadget camber_gad = {
  305.    NULL,                        /* First gadget */
  306.    10L,50L,100L,11L,            /* LeftEdge, TopEdge, Width, Height */
  307.    GADGHCOMP,                   /* Complement image for select */
  308.    LONGINT |                    /* This is an integer gadget */
  309.    RELVERIFY,                   /* Release verify */
  310.    STRGADGET |                  /* This is a string gadget */
  311.    REQGADGET,                   /* This is a requester gadget */
  312.    NULL,                        /* No gadget image */
  313.    NULL,                        /* No selected image */
  314.    &camber_text,                /* GadgetText */
  315.    0,                           /* No mutual exclusion */
  316.    (APTR)&camber_string,        /* SpecialInfo */
  317.    CAMBER_GAD,                  /* Gadget id */
  318.    NULL                         /* No user data */
  319. };
  320.  
  321. #define THICK_GAD 1
  322. struct Gadget thick_gad = {
  323.    &camber_gad,                 /* NextGadget */
  324.    10L,80L,100L,11L,            /* LeftEdge, TopEdge, Width, Height */
  325.    GADGHCOMP,                   /* Complement image for select */
  326.    LONGINT |                    /* This is an integer gadget */
  327.    RELVERIFY,                   /* Release verify */
  328.    STRGADGET |                  /* This is a string gadget */
  329.    REQGADGET,                   /* This is a requester gadget */
  330.    NULL,                        /* No gadget image */
  331.    NULL,                        /* No selected image */
  332.    &thick_text,                 /* GadgetText */
  333.    0,                           /* No mutual exclusion */
  334.    (APTR)&thick_string,         /* SpecialInfo */
  335.    THICK_GAD,                   /* Gadget id */
  336.    NULL                         /* No user data */
  337. };
  338.  
  339. #define ANGLE_GAD 2
  340. struct Gadget angle_gad = {
  341.    &thick_gad,                  /* NextGadget */
  342.    10L,110L,100L,11L,           /* LeftEdge, TopEdge, Width, Height */
  343.    GADGHCOMP,                   /* Complement image for select */
  344.    LONGINT |                    /* This is an integer gadget */
  345.    RELVERIFY,                   /* Release verify */
  346.    STRGADGET |                  /* This is a string gadget */
  347.    REQGADGET,                   /* This is a requester gadget */
  348.    NULL,                        /* No gadget image */
  349.    NULL,                        /* No selected image */
  350.    &angle_text,                 /* GadgetText */
  351.    0,                           /* No mutual exclusion */
  352.    (APTR)&angle_string,         /* SpecialInfo */
  353.    ANGLE_GAD,                   /* Gadget id */
  354.    NULL                         /* No user data */
  355. };
  356.  
  357. #define VELOCITY_GAD 3
  358. struct Gadget velocity_gad = {
  359.    &angle_gad,                  /* NextGadget */
  360.    0L,138L,199L,11L,            /* LeftEdge, TopEdge, Width, Height */
  361.    GADGHCOMP,                   /* Complement image for select */
  362.    RELVERIFY,                   /* Release verify */
  363.    PROPGADGET |                 /* This is a proportional gadget */
  364.    REQGADGET,                   /* This is a requester gadget */
  365.    (APTR)&prop_image,           /* Gadget image */
  366.    NULL,                        /* No selected image */
  367.    &velocity_text,              /* GadgetText */
  368.    0,                           /* No mutual exclusion */
  369.    (APTR)&velocity_prop,        /* SpecialInfo */
  370.    VELOCITY_GAD,                /* Gadget id */
  371.    NULL                         /* No user data */
  372. };
  373.  
  374. #define AIRFOIL_GAD 4
  375. struct Gadget airfoil_gad = {
  376.    &velocity_gad,               /* NextGadget */
  377.    84L,15L,32L,22L,             /* LeftEdge, TopEdge, Width, Height */
  378.    GADGHIMAGE |                 /* Use alternate image for select */
  379.    GADGIMAGE,                   /* Render gadget as an image */
  380.    TOGGLESELECT |               /* Toggle gadget each time it is selected */
  381.    GADGIMMEDIATE,               /* Signal me when user selects gadget */
  382.    BOOLGADGET |                 /* This is a boolean gadget */
  383.    REQGADGET,                   /* This is a requester gadget */
  384.    (APTR)&stream_image,         /* Pointer to gadget image */
  385.    (APTR)&pressure_image,       /* Pointer to selected image */
  386.    NULL,                        /* No text */
  387.    0,                           /* No mutual exclusion */
  388.    NULL,                        /* No special info */
  389.    AIRFOIL_GAD,                 /* Gadget id */
  390.    NULL                         /* No user data */
  391. };
  392.  
  393. #define TITLE_GAD 5
  394. struct Gadget title_gad = {
  395.    &airfoil_gad,                /* NextGadget */
  396.    24L,0L,151L,10L,             /* LeftEdge, TopEdge, Width, Height */
  397.    GADGHCOMP,                   /* Complement image for select */
  398.    TOGGLESELECT |               /* Toggle gadget each time it is selected */
  399.    GADGIMMEDIATE,               /* Signal me when user selects gadget */
  400.    BOOLGADGET |                 /* This is a boolean gadget */
  401.    REQGADGET,                   /* This is a requester gadget */
  402.    (APTR)&title_border,         /* Pointer to gadget image */
  403.    NULL,                        /* No selected image */
  404.    NULL,                        /* No text */
  405.    0,                           /* No mutual exclusion */
  406.    NULL,                        /* No special info */
  407.    TITLE_GAD,                   /* Gadget id */
  408.    NULL                         /* No user data */
  409. };
  410.  
  411. #define CLOSE_GAD 6
  412. struct Gadget close_gad = {
  413.    &title_gad,                  /* NextGadget */
  414.    176L,0L,24L,10L,             /* LeftEdge, TopEdge, Width, Height */
  415.    GADGHCOMP |                  /* Complement image for select */
  416.    GADGIMAGE,                   /* Render gadget as an image */
  417.    GADGIMMEDIATE |              /* Signal me when user selects gadget */
  418.    RELVERIFY |                  /* Release verify */
  419.    ENDGADGET,                   /* This gadget ends requester */
  420.    BOOLGADGET |                 /* This is a boolean gadget */
  421.    REQGADGET,                   /* This is a requester gadget */
  422.    (APTR)&close_image,          /* Pointer to gadget image */
  423.    NULL,                        /* No selected image */
  424.    NULL,                        /* No text */
  425.    0,                           /* No mutual exclusion */
  426.    NULL,                        /* No special info */
  427.    CLOSE_GAD,                   /* Gadget id */
  428.    NULL                         /* No user data */
  429. };
  430.  
  431. #define QUIT_GAD 7
  432. struct Gadget quit_gad = {
  433.    &close_gad,                  /* NextGadget */
  434.    0L,0L,24L,10L,               /* LeftEdge, TopEdge, Width, Height */
  435.    GADGHCOMP |                  /* Complement image for select */
  436.    GADGIMAGE,                   /* Render gadget as an image */
  437.    GADGIMMEDIATE |              /* Signal me when user selects gadget */
  438.    RELVERIFY |                  /* Release verify */
  439.    ENDGADGET,                   /* This gadget ends requester */
  440.    BOOLGADGET |                 /* This is a boolean gadget */
  441.    REQGADGET,                   /* This is a requester gadget */
  442.    (APTR)&quit_image,           /* Pointer to gadget image */
  443.    NULL,                        /* No selected image */
  444.    NULL,                        /* No text */
  445.    0,                           /* No mutual exclusion */
  446.    NULL,                        /* No special info */
  447.    QUIT_GAD,                    /* Gadget id */
  448.    NULL                         /* No user data */
  449. };
  450.  
  451. struct NewScreen ns = {
  452.    0L, 0L,                      /* LeftEdge, TopEdge */
  453.    640L, 400L, 4L,              /* Width, Height, Depth */
  454.    0L, 1L,                      /* DetailPen, BlockPen */
  455.    HIRES |                      /* ViewMode flags */
  456.    LACE,
  457.    CUSTOMSCREEN,                /* Type */
  458.    NULL,                        /* Default Font */
  459.  
  460.    (UBYTE *)"JOUKOWSKI AIRFOIL GENERATOR",
  461.  
  462.    NULL,                        /* No custom gadgets */
  463.    NULL                         /* No CustomBitMap */
  464. };
  465.  
  466. struct NewWindow nw = {
  467.    0L, 0L,                      /* LeftEdge, TopEdge */
  468.    640L, 400L,                  /* Width, Height */
  469.    0L, 1L,                      /* DetailPen, BlockPen */
  470.    GADGETDOWN |                 /* IDCMP flags */
  471.    GADGETUP |
  472.    REQVERIFY |
  473.    REQCLEAR,
  474.    SMART_REFRESH |              /* Flags */
  475.    ACTIVATE |
  476.    BACKDROP,
  477.    NULL,                        /* No gadgets in window */
  478.    NULL,                        /* Use default checkmark */
  479.    NULL,                        /* No Title */
  480.    NULL,                        /* Pointer to screen, to be set later */
  481.    NULL,                        /* No superbitmap is used */
  482.    0L, 0L, 0L, 0L,              /* Window is not resizable */
  483.    CUSTOMSCREEN                 /* Screen Type */
  484. };
  485.